// index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currProduct:[],
    selList:"",
    pmId:"",
    storeid: app.globalData.storeId
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    console.log(e.pmid);
    var that=this;
    var selList = e.selList;
    that.setData({
      selList: selList,
      pmId: e.pmid
    })
    that.getGift(e.pmid);
  },

  // 获得满赠赠品http://weapp.711688.net.cn/api/Cart/GetFullSend?pmId=11
  getGift: function (pmid){
    var that = this;
     wx.request({
       url: app.globalData.host + '/api/Cart/GetFullSend?pmId=' + pmid,
       success: function (res) {
         console.log(res.data.Data);
         if (res.data.Code == 0) {
           that.setData({
             currProduct: res.data.Data
           })
         }
       }
     })
  },
  //赠品加入购物车
  addcart:function(e){
    this.delectGift();
    console.log(e);
    var pid = e.currentTarget.dataset.pid;
    var that=this;
    wx.request({
      url: app.globalData.host + '/api/Cart/AddFullSend',
      data:{
        pmId:that.data.pmId,
        pid:pid,
        uid: app.globalData.userInfo.Uid,
        selList: that.data.selList
      },
      success:function(res){
        console.log(res);
        if(res.data.Code==0){
          wx.showToast({
            title: '选择赠品成功',
            icon: 'success',
            duration: 2000,
            success:function(){
              wx.navigateBack({
                delta: 1,
              })
            }
          })
        }
        
      }
    })
  },
// 删除购物车中满赠商品POST /api/Cart/DelFullSend
delectGift:function(){
  var that = this;
  console.log(that.data.pmId)
  wx.request({
    url: app.globalData.host + '/api/Cart/DelFullSend',
    data: {
      pmId: that.data.pmId,
      uid: app.globalData.userInfo.Uid,
      selList: that.data.selList
    },
    success: function (res) {
      console.log(res);
      if (res.data.Code == 0) {
      }
    }
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})